//
//  ZHFPhotoFootView.m
//  GoTraveling
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "ZHFPhotoFootView.h"

#import "ZHFPhoto.h"

#import "WSTools.h"

@interface ZHFPhotoFootView ()

@property (nonatomic, retain) UILabel *label;

@property (nonatomic, retain) UIScrollView *scrollView;

@property (nonatomic, retain) UILabel *timeLabel;

@property (nonatomic, retain) UIImageView *timeImage;

@end

@implementation ZHFPhotoFootView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.frame.size.height - 30)];
    [self addSubview:self.scrollView];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, 64)];
    self.label.numberOfLines = 0;
    self.label.textColor = [UIColor whiteColor];
    self.label.font = [UIFont systemFontOfSize:14];
    [self.scrollView addSubview:self.label];
    
    self.timeImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, self.frame.size.height - 23, 15, 15)];
    self.timeImage.tintColor = [UIColor whiteColor];
    self.timeImage.image = [[UIImage imageNamed:@"clock_gray_big"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.timeImage.layer.cornerRadius = 8;
    self.timeImage.layer.masksToBounds = YES;
    [self addSubview:self.timeImage];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, self.frame.size.height - 30, SCREEN_WIDTH, 30)];
    self.timeLabel.textColor = [UIColor whiteColor];
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:self.timeLabel];
}

- (void)setPhoto:(ZHFPhoto *)photo {
    
    self.label.text = photo.descriptions;
    CGFloat height = [WSTools heightForContent:photo.descriptions size:14];
    CGRect frame = self.label.frame;
    frame.size.height = height;
    CGFloat y = self.scrollView.frame.size.height - height;
    frame.origin.y = y < 0 ? 0 : y;
    self.label.frame = frame;
    
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.frame = CGRectMake(0, 20, SCREEN_WIDTH, self.scrollView.frame.size.height);
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, height);
    self.timeImage.hidden = YES;
    self.timeLabel.hidden = YES;
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
